package com.davidk.survey.server.model.smartgwtrest;

import java.util.List;

public class FetchResponse<T> extends Response {
	private int startRow;
	private int endRow;
	private int totalRows;
	private List<T> data;

	public void setStartRow(int startRow) {
		this.startRow = startRow;
		validate();
	}

	public int getStartRow() {
		return startRow;
	}

	public void setEndRow(int endRow) {
		this.endRow = endRow;
	}

	public int getEndRow() {
		return endRow;
	}

	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
	}

	public int getTotalRows() {
		return totalRows;
	}

	public void setData(List<T> data) {
		this.data = data;
		validate();
	}

	public List<T> getData() {
		return data;
	}

	private void validate() {
		if (data != null)
			endRow = startRow + data.size();
		else
			endRow = startRow;
		if (totalRows < endRow - startRow)
			totalRows = endRow - startRow;
	}
}
